from app import app, lm
from .models import User, Product
from flask_login import login_user, logout_user, current_user
from flask import render_template, redirect, url_for, flash, request, g
from .blueprints.index import index_page
from .blueprints.bop_server import bop_server_page
from .blueprints.middle_server import middle_server_page
from .blueprints.database_server import database_server_page
from .blueprints.permissions_add import permissions_add_page
from .blueprints.approval import approval_page
from .blueprints.login import login_page
from .blueprints.register import register_page
from .blueprints.turn import turn_page
from .blueprints.histurn import histurn_page
from .blueprints.all_server import all_server_page
from .blueprints.bop_jar_version import bop_jar_version_page
from .blueprints.A import A_plan_page
import time


@lm.user_loader
def load_user(id):
    return User.query.get(int(id))


@app.route('/logout')
def logout():
    logout_user()
    return redirect('/login')


@app.before_request
def before_request():
    g.user = current_user


app.register_blueprint(index_page)
app.register_blueprint(bop_server_page)
app.register_blueprint(middle_server_page)
app.register_blueprint(database_server_page)
app.register_blueprint(permissions_add_page)
app.register_blueprint(approval_page)
app.register_blueprint(login_page)
app.register_blueprint(register_page)
app.register_blueprint(turn_page)
app.register_blueprint(histurn_page)
app.register_blueprint(all_server_page)
app.register_blueprint(bop_jar_version_page)
app.register_blueprint(A_plan_page)
